let form1=document.querySelector('form')
// let errBox=document.querySelector('.error');
let nameInp1=document.querySelector('.username');
let pwdInp1=document.querySelector('.rename');
let supwdInp=document.querySelector('.suname');
// let nickInp=document.querySelector('.nick');


async function fn() {
    let re=await isLogin();
    console.log(re)
}
form1.addEventListener('submit',async e=>{
    e.preventDefault();
    let oldPassword=nameInp1.value
    let newPassword=pwdInp1.value;
    let rNewPassword=supwdInp.value;
    let id=localStorage.getItem('id')

    if(!oldPassword||!newPassword||!rNewPassword) return alert('请完整填写表单');
    if(newPassword!=rNewPassword) return alert('两次密码不一致');
    // let res = await http.post('/users/register',{name,pwd,supwd,nick});
    // console.log(res)
    // data={oldPassword,newPassword,rNewPassname}
    // let {config} = await http.post('/users/rpwd',{oldPassword,newPassword,rNewPassword});
    // console.log(config)

    let {data} = await http.post('/users/rpwd',{id,oldPassword,newPassword,rNewPassword});
    console.log(data)
    if(data.code!=1){
        alert('请重试')
    }
    if(data.code==1){
        alert('恭喜修改成功，点击确定跳转登录页面！')
        location.href='./login.html';
    }
})